<?php
class RolsController extends AppController {

	var $name = 'Rols';
	var $helpers = array('Html', 'Form', 'Y');
	var $components = array('Y');

	function index() {
		$this->Rol->recursive = 0;
		$this->set('rols', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Rol.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('rol', $this->Rol->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Rol->create();
			if ($this->Rol->save($this->data)) {
				$this->Session->setFlash(__('The Rol has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Rol could not be saved. Please, try again.', true));
			}
		}
		$users = $this->Rol->User->find('list');
		$tiporols = $this->Rol->Tiporol->find('list');
		$grupos = $this->Rol->Grupo->find('list');
		$this->set(compact('users', 'tiporols', 'grupos'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Rol', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Rol->save($this->data)) {
				$this->Session->setFlash(__('The Rol has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Rol could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Rol->read(null, $id);
		}
		$users = $this->Rol->User->find('list');
		$tiporols = $this->Rol->Tiporol->find('list');
		$grupos = $this->Rol->Grupo->find('list');
		$this->set(compact('users','tiporols','grupos'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Rol', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Rol->delete($id)) {
			$this->Session->setFlash(__('Rol deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>